﻿using ETask.Api.Models;
using System.Linq.Expressions;

namespace ETask.Api.Repositories
{
    /// <summary>
    /// 通用仓储接口
    /// </summary>
    /// <typeparam name="T">实体类型</typeparam>
    public interface IRepository<T> where T : BaseEntity
    {
        /// <summary>
        /// 获取所有实体（分页）
        /// </summary>
        Task<PagedResult<T>> GetPagedAsync(PaginationParameters paginationParameters);

        /// <summary>
        /// 根据条件查询（分页）
        /// </summary>
        Task<PagedResult<T>> FindAsync(Expression<Func<T, bool>> predicate, PaginationParameters paginationParameters);

        Task<List<T>> FindAllAsync(Expression<Func<T, bool>> predicate);

        /// <summary>
        /// 根据ID获取实体
        /// </summary>
        Task<T> GetByIdAsync(int id);

        /// <summary>
        /// 添加实体
        /// </summary>
        Task AddAsync(T entity);

        /// <summary>
        /// 更新实体
        /// </summary>
        Task UpdateAsync(T entity);

        /// <summary>
        /// 删除实体
        /// </summary>
        Task DeleteAsync(int id);

        /// <summary>
        /// 保存更改
        /// </summary>
        Task SaveChangesAsync();
    }
}
